﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MessageBoard2 : System.Web.UI.Page
{
    MessageBoardDBDataContext db = new MessageBoardDBDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        Listupdate();
    }

    protected void Bt_message_Click(object sender, EventArgs e)
    {
        LeavingMessage2 lm = new LeavingMessage2();
        lm.name = Session["username"].ToString();
        lm.message = tb_liuyan.Text;
        lm.posttime = System.DateTime.Now;
        db.LeavingMessage2.InsertOnSubmit(lm);
        db.SubmitChanges();
        Listupdate();
    }

    private void Listupdate()
    {
        var results = from r in db.LeavingMessage2
                      select new
                      {
                          r.name,
                          r.id,
                          r.posttime,
                          r.message,
                      };
        DataList1.DataSource = results;
        DataList1.DataBind();
    }

    protected void Bt_delmessage_Click(object sender, EventArgs e)
    {
        string tmp = (sender as LinkButton).CommandArgument;
        int id = int.Parse(tmp);
        var results = from r in db.LeavingMessage2
                      where r.id == id
                      select r;
        db.LeavingMessage2.DeleteAllOnSubmit(results);
        db.SubmitChanges();
        Listupdate();
    }
}